{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 第四次练习"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "+ 请务必交到exer4文件夹下，谢绝交到master下\n",
    "+ 请不要改动任何文件，拜托\n",
    "+ 请在10月30日前提交。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "请写一下姓名和学号：\n",
    "+ 姓名 易扬  \n",
    "+ 学号 0174922"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目一\n",
    "一般的歌，分为主歌和副歌部分。副歌有重复，对比两大功能。这就是A－B的基本曲式形式结构。  \n",
    "请找一首你的主打歌，把歌词打印出来，重复的副歌部分，请写一个函数，调用函数打印出来。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "我想摸你的头发\n",
      "\n",
      "只是简单的试探啊\n",
      "\n",
      "\n",
      "我能送你回家吗\n",
      "\n",
      "可能外面要下雨啦\n",
      "\n",
      "我能给你个拥抱\n",
      "\n",
      "像朋友一样可以吗\n",
      "\n",
      "\n",
      "\n",
      "我能送你回家吗\n",
      "\n",
      "可能外面要下雨啦\n",
      "\n",
      "我能给你个拥抱\n",
      "\n",
      "像朋友一样可以吗\n",
      "\n",
      "\n",
      "\n",
      "我能送你回家吗\n",
      "\n",
      "可能外面要下雨啦\n",
      "\n",
      "我能给你个拥抱\n",
      "\n",
      "像朋友一样可以吗\n",
      "\n",
      "\n",
      "你就当刚认识的绅士\n",
      "\n",
      "闹了个笑话吧\n"
     ]
    }
   ],
   "source": [
    "print('''\n",
    "我想摸你的头发\n",
    "\n",
    "只是简单的试探啊\n",
    "''')\n",
    "def  repeat():\n",
    "    print('''\n",
    "我能送你回家吗\n",
    "\n",
    "可能外面要下雨啦\n",
    "\n",
    "我能给你个拥抱\n",
    "\n",
    "像朋友一样可以吗\n",
    "\n",
    "''')\n",
    "repeat()\n",
    "repeat()\n",
    "repeat()\n",
    "print('''你就当刚认识的绅士\n",
    "\n",
    "闹了个笑话吧''')\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目二\n",
    "请写一个函数，能够计算均值、样本方差和n(自己写公式哦)。\n",
    "每次输入十个以上的数字，能够输出上述三个统计量。\n",
    "至少调用两次。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "均值是(保留两位小数）5.46\n",
      "\n",
      "样本方差是(保留两位小数）4.56\n",
      "\n",
      "标准差是(保留两位小数）2.13\n",
      "\n",
      "均值是(保留两位小数）5.45\n",
      "\n",
      "样本方差是(保留两位小数）3.16\n",
      "\n",
      "标准差是(保留两位小数）1.78\n"
     ]
    }
   ],
   "source": [
    "def formula(*numbers):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for number in numbers:\n",
    "        a=a+number\n",
    "        n+=1\n",
    "        average=a/n\n",
    "    print(\"\\n均值是(保留两位小数）%s\"%round(average,2))\n",
    "    for number in numbers:\n",
    "        b=b+(number-average)**2\n",
    "        varian=b/n\n",
    "    print(\"\\n样本方差是(保留两位小数）%s\"%round(varian,2))\n",
    "    print(\"\\n标准差是(保留两位小数）%s\"%round(varian**0.5,2))\n",
    "formula(2,9,5,5,7,6,6,6,5,2,3,9,6)\n",
    "formula(5,5,7,6,6,6,5,2,3,9,6)\n",
    "\n",
    "\n",
    "        \n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目三\n",
    "刚才那个函数，默认的是输出均值、样本方差和n，请在后面添加一个关键词参数，让这个函数可以选择输出样本标准差或方差。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "想输出样本标准差请输入1，想输出方差请输入21\n",
      "\n",
      "样本标准差是(保留两位小数）2.13\n"
     ]
    }
   ],
   "source": [
    "def formula(*numbers):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for number in numbers:\n",
    "        a=a+number\n",
    "        n+=1\n",
    "        average=a/n\n",
    "    for number in numbers:\n",
    "        b=b+(number-average)**2\n",
    "        varian=b/n\n",
    "    d = int(input(\"\\n想输出样本标准差请输入1，想输出方差请输入2\"))\n",
    "    if d== 1:\n",
    "        print(\"\\n样本标准差是(保留两位小数）%s\"%round(varian**0.5,2))  \n",
    "    else:\n",
    "        print(\"\\n样本方差是(保留两位小数）%s\"%round(varian,2))\n",
    "formula(2,9,5,5,7,6,6,6,5,2,3,9,6)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 题目四\n",
    "刚才那个函数，请再增加三个关键词参数，让这个参数可以选择输出均值的标准误、最大值、最小值或不输出这三个统计量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "需要打印均值标准误请输入1，不需要则输入其他？2\n",
      "\n",
      "需要打印最大值请输入1，不需要则输入其他？1\n",
      "样本中的最大值9\n",
      "\n",
      "需要打印最小值请输入1，不需要则输入其他？1\n",
      "样本中的最小值2\n"
     ]
    }
   ],
   "source": [
    "def formula(max=None,min=None,*numbers):\n",
    "    a=0\n",
    "    b=0\n",
    "    n=0\n",
    "    for number in numbers:\n",
    "        a=a+number\n",
    "        n+=1\n",
    "        average=a/n\n",
    "    for number in numbers:\n",
    "        b=b+(number-average)**2\n",
    "        varian=b/n\n",
    "        d = (b/(n**3))**0.5\n",
    "    for number in numbers:\n",
    "        if number>max:\n",
    "            max=number\n",
    "    for number in numbers:\n",
    "        if number<min:\n",
    "            min=number\n",
    "    e1 = int(input(\"\\n需要打印均值标准误请输入1，不需要则输入其他？\"))\n",
    "    if e1==1:\n",
    "        print(\"样本标准误为%s\"%round(d,2))\n",
    "    e2 = int(input(\"\\n需要打印最大值请输入1，不需要则输入其他？\"))\n",
    "    if e2==1:\n",
    "         print(\"样本中的最大值%s\"%max)\n",
    "    e3 = int(input(\"\\n需要打印最小值请输入1，不需要则输入其他？\"))\n",
    "    if e3==1:\n",
    "        print(\"样本中的最小值%s\"%min)   \n",
    "formula(2,9,5,5,7,6,6,6,5,2,3,9,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
